< previous page page_534 next page >

Page 534
z0554-01.gif
Figure 15.3
The cross-product of two adjacent vectors on a face
gives an outward-pointing surface normal.
The value of Cos(q) is greater than zero if q is less than 90 degrees. It is less than zero if q is greater than 90 degrees. Finally, Cos(q) equals zero if q equals 90 degrees. Because the lengths |A| and |B| are always positive, the dot product A B is greater than zero if and only if Cos(q) > 0 and therefore q < 90 degrees.
Putting It All Together
Using cross-products and dot products, you can implement the backface removal algorithm in Visual Basic. For each surface in the solid:
1. Take the cross-product of the first two edges of the surface to get an outward-pointing normal vector.
2. Take the dot product of the normal vector and the viewing direction. If the result is less than or equal to zero, the surface is a backface (or seen edge on), so you do not need to draw it.
Backface removal eliminates roughly half of the surfaces you need to consider when drawing three-dimensional solids. If necessary, you can then use one of the more complicated algorithms described later in this chapter to determine which parts of the remaining surfaces you should draw.
Convex Solids
A solid is convex if the angles between each of its adjacent surfaces are all greater than zero degrees. This means there are no nooks, crannies, or holes in the solid. Another way to think of this is to imagine extending each of the solid's surfaces infinitely in all directions. If none of the extended surfaces cuts through the body of the solid, the solid is convex. The solid on the left in Figure 15.4 is convex; the solid on the right is not.
If you are drawing a single convex solid, backface removal identifies all the surfaces that you should draw. All the backfaces are completely hidden, and all other surfaces are completely visible. The solid on the left in Figure 15.4 has four backfaces drawn with dashed lines. The other four surfaces are not backfaces and they are completely visible.

 
< previous page page_534 next page >